﻿using AutoMapper;
using B.S.Ingredients.APIRead.Application.Command.EnterCommand;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.EnterCommandHandler
{
    public class EnterCreateCommandHandler : IRequestHandler<EnterCreateCommand, APIResult<int>>
    {
        public EnterCreateCommandHandler(IBaseRepository<EnterClass> EnterClassRepository,IMapper mapper)
        {
            this.EnterClassRepository = EnterClassRepository;
            Mapper = mapper;
        }

        public IBaseRepository<EnterClass> EnterClassRepository { get; }
        public IMapper Mapper { get; }

        public async Task<APIResult<int>> Handle(EnterCreateCommand request, CancellationToken cancellationToken)
        {
            var path = await EnterClassRepository.CreateAsync(Mapper.Map<EnterClass>(request));
            return new APIResult<int>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };

        }
    }
}
